package com.lh.service.impl;

import com.lh.mapper.CarouselMapper;
import com.lh.mapper.CategoryExtMapper;
import com.lh.mapper.CategoryMapper;
import com.lh.pojo.Carousel;
import com.lh.pojo.Category;
import com.lh.pojo.vo.CategoryVO;
import com.lh.pojo.vo.ItemVO;
import com.lh.service.CarouselService;
import com.lh.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * @program: foodie-dev
 * @description:
 * @author: LH
 * @create: 2022-04-28 14:47
 **/
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private CategoryExtMapper categoryExtMapper;


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Category> getCategory(Integer cateType) {

        Example example = new Example(Category.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("type", cateType);

        List<Category> categoryList = categoryMapper.selectByExample(example);
        return categoryList;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<CategoryVO> getSubCategory(Integer rootCatId) {

        List<CategoryVO> categoryVOList = categoryExtMapper.getSubCategory(rootCatId);
        return categoryVOList;
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<ItemVO> getSixNewItems(Map<String, Integer> map) {

        List<ItemVO> itemVOList = categoryExtMapper.getSixNewItems(map);
        return itemVOList;
    }
}
